<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
    <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
    <%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <meta name="renderer" content="webkit">
    <%@ include file="top_new.jsp"%> 
    <link rel="stylesheet" href="/common/bootstrap/css/bootstrap.min.css" media="all" />
</head>
<body>
  <div class="panel admin-panel">
  <div class="padding border-bottom layui-form-item">
    <div class="layui-input-inline">
      <select class="form-control" id = "fcode">
	       <option value="" >--字典分类--</option>
	        <c:forEach items="${tdic}" var="s">
				<option value="${s.fode}" >【${s.fode}】${s.fvalue}</option>
			</c:forEach>
   	   </select>
    </div>
    <div class="layui-input-inline">
      <select class="form-control" id = "userid">
	       <option value="" >--用户列表--</option>
	        <c:forEach items="${users}" var="u">
				<option value="${u.fnickname}" >${u.fnickname}</option>
			</c:forEach>
   	   </select>
    </div>
    <button class="layui-btn" id ="query">查询</button>
    <button class="layui-btn" id ="bt_add">添加</button>
    <button class="layui-btn" id ="bt_dell">删除</button>
  </div>
		<div >
			<table class="layui-table">
			  <colgroup>
			    <col width="20">
			    <col width="100">
			  </colgroup>
			  <thead>
			    <tr>
			      <th name ="fid" id="fid"><input type='checkbox' id ='selected-all'/></td></th>
			      <th name ="fsequence" id="fsequence">序列码</th>
			      <th name ="ftype" id="ftype">游戏类别</th>
			      <th name ="fcycle" id="fcycle">有效天数</th>
			      <th name ="fcreateTime" id="fcreateTime">生成日期</th>
			      <th name ="factivTime" id="factivTime">激活日期</th>
			      <th name ="fendTime" id="fendTime">到期日期</th>
			      <th name ="fuserid" id="fuserid">操作人</th>
			      <th name ="fremark" id="fremark">备注</th>
			      <th >操作</th>
			    </tr> 
			  </thead>
			  <tbody id = "t_tbody">
			  </tbody>
			    <tr>
			       <td colspan="10"><div id="div_page"></div></td>
			    </tr>
			</table> 
		</div> 
  </div>
<script type="text/javascript"> 
$("#bt_add").click(function(){
    var diag = new top.Dialog();
    diag.Drag=true;
    diag.Title ="新增序列码";
    diag.URL = '<%=basePath%>seqCode/seqCode_edit';
    diag.Width = 400;
    diag.Height = 400;
    diag.CancelEvent = function(){ //关闭事件
    	var isLoad = diag.innerFrame.contentWindow.document.getElementById("isLoad").value;
    	if(isLoad == '1'){
    		queryList();
    	}
        diag.close();
    };
    diag.show();
});
$("#selected-all").click(function(){ 
	var status = $(this).prop("checked");
	$("input[id='id']").prop("checked",status); 
})
window.onload=function() {
	$.post("<%=basePath%>seqCode/seqCode_list",
		    {
				page:1,
				pagesize:10
		    },
		    function(res){
		    	if (res.errorCode == 0) {
		    		var data = res.data;
		    		laypage({
		    		      cont: 'div_page', //容器。值支持id名、原生dom对象，jquery对象。【如该容器为】：<div id="page1"></div>
		    		      pages: data.totalPage, //通过后台拿到的总页数
		    		      curr: data.pageNumber, //当前页
		    		      jump: function(obj, first){ //触发分页后的回调
		    		    	  $("#t_tbody").empty();
		    		    	  if(!first){
			    		    	  $.post("<%=basePath%>seqCode/seqCode_list",
			    		    			    {
			    		    					page:obj.curr,
			    		    					pagesize:10,
			    		    					fvalue:$("#fcode").val(),
			    		    					userid:$("#userid").val()
			    		    			    },
			    		    			    function(res){
			    		    			    	var tbody ="";
		    		    			    		if (res.errorCode == 0) {
			    		    			    		 tbody = pageDataCode(res.data.list,0);  
		    		    			    		}
		    		    			    		$("#t_tbody").append(tbody);  
			    		    			    });
		    		    	  }else{
		    		    		   var tbody ="";
		    		    		   tbody = pageDataCode(data.list,0);  
		    			    	   $("#t_tbody").append(tbody);  
		    		    	  }
		    		    	 
		    		      }
		    		});
		    	}else{
		    		if (res.errorCode == 2) {
		    			layer.alert(res.message) ;
		    		}else{
		    			layer.msg("参数错误："+res.message, {shift: 6});
		    		}
		    	}
		    }); 
};
$("#query").click(function(){ 
	 queryList();
});
function queryList(){
	 var fsortcode = $("#fcode").val();
	 $.post("<%=basePath%>seqCode/seqCode_list",
			    {
					page:1,
					pagesize:10,
					fcode:fsortcode,
			    	userid:$("#userid").val()
			    },
			    function(res){
			    	if (res.errorCode == 0) {
			    		var data=res.data;
			    		laypage({
			    		      cont: 'div_page', //容器。值支持id名、原生dom对象，jquery对象。【如该容器为】：<div id="page1"></div>
			    		      pages: data.totalPage, //通过后台拿到的总页数
			    		      curr: data.pageNumber, //当前页
			    		      jump: function(obj, first){ //触发分页后的回调
			    		    	  $("#t_tbody").empty();
			    		    	  $.post("<%=basePath%>seqCode/seqCode_list",
			    		    			    {
			    		    					page:obj.curr,
			    		    					pagesize:10,
			    		    					fcode:fsortcode,
			    								userid:$("#userid").val()
			    		    			    },
			    		    			    function(res){
		    		    			    		if (res.errorCode == 0) {
		    		    			    			var tbody ="";
			    		    			    		if (res.errorCode == 0) {
				    		    			    		 tbody = pageDataCode(res.data.list,0);  
			    		    			    		}
			    		    			    		$("#t_tbody").append(tbody);   
		    		    			    		}
			    		    			    });
			    		      }
			    		});
			    	}else{
			    		if (res.errorCode == 2) {
			    			layer.alert(res.message) ;
			    		}else{
			    			layer.msg("参数错误："+res.message, {shift: 6});
			    		}
			    	}
			    }); 
}
function del(fid){
	var id =  new Array();
	id[0] = fid;
	layer.confirm('确定需要删除所选记录？', {
				icon: 1,btn: ['确定','取消'] //按钮
	},function(){
		 $.post("<%=basePath%>seqCode/delSeq",
		    {
				id:id
		    },
		    function(ret){
	    		if (ret.isOk) {
    				layer.msg(ret.msg+"条数据删除成功！", {shift: 1});
    				queryList();
    				return true;
    			} else {
    				layer.msg(ret.msg, {shift: 6});
    				return false;
    			}
		    });
	},function(){
		//返回列表
	});
}
$("#bt_dell").click(function(){
	var id =  new Array();
	$("table input[type=checkbox]:checked").each(function(i){
		id[i] = $(this).val();
	});
	if(id.length <= 0){
		layer.msg("请选择需要删除的记录.", {shift: 6});
		return false;
	}
	layer.confirm('确定需要删除所选记录？', {
				icon: 1,btn: ['确定','取消'] //按钮
		},function(){
    		 $.post("<%=basePath%>seqCode/delSeq",
			    {
					id:id
			    },
			    function(ret){
		    		if (ret.isOk) {
	    				layer.msg(ret.msg+"条数据删除成功！", {shift: 1});
	    				queryList();
	    				return true;
	    			} else {
	    				layer.msg(ret.msg, {shift: 6});
	    				return false;
	    			}
			    });
		},function(){
			//返回列表
		});
});
function edit(id){
	var diag = new top.Dialog();
    diag.Drag=true;
    diag.Title ="新增序列码";
    diag.URL = '<%=basePath%>seqCode/seqCode_edit?fid='+id;
    diag.Width = 400;
    diag.Height = 400;
    diag.CancelEvent = function(){ //关闭事件
    	var isLoad = diag.innerFrame.contentWindow.document.getElementById("isLoad").value;
    	if(isLoad == '1'){
    		queryList();
    	}
        diag.close();
    };
    diag.show();
}
</script>
</body></html>